home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Oh!X 2001 Spring
/
Oh!X 2001 Spring Special CD-ROM (Japan).7z
/
Oh!X 2001 Spring Special CD-ROM (Japan) (Track 1).bin
/
FBENC
/
TEC-FB^3.sea
/
TEC-FB^3
/
TEC2.MAIN
< prev
next >
Wrap
Text File
|
2000-07-05
|
3KB
|
110 lines
/*
Text Encoding Converter Example #2
Takaaki Mizuno(takaaki@cds.ne.jp)
2000.7.5
*/
DIM xErr AS OSStatus
DIM inputEncoding AS TextEncoding
DIM outputEncoding AS TextEncoding
DIM converter AS TECObjectRef
DIM inputact AS ByteCount
DIM outputact AS ByteCount
DIM a$, b$
DIM d AS BYTE
END GLOBALS
CLEAR LOCAL
LOCAL FN FindBestEncoding&(string AS STR255)
DIM err AS OSStatus
DIM maxRegionEncodings AS ItemCount
DIM actualRegionEncodings AS ItemCount
DIM maxSnifferEncodings AS ItemCount
DIM actualSnifferEncodings AS ItemCount
DIM regionEncodings AS POINTER TO TextEncoding
DIM snifferEncodings AS POINTER TO TextEncoding
DIM sniffer AS TECSnifferObjectRef
DIM errors AS POINTER TO ItemCount
DIM features AS POINTER TO ItemCount
DIM loop AS INTEGER
DIM loop2 AS INTEGER
DIM locale AS INTEGER
DIM bestEncoding AS TextEncoding
DIM found AS BOOLEAN
locale = 14 //verJapan
err = FN TECCountWebTextEncodings(locale, @maxRegionEncodings)
regionEncodings = 0
regionEncodings = FN NewPtrClear (SIZEOF(TextEncoding) * maxRegionEncodings)
LONG IF regionEncodings>0
err = FN TECGetWebTextEncodings (locale, regionEncodings,maxRegionEncodings, @actualRegionEncodings)
err = FN TECCountAvailableSniffers (@maxSnifferEncodings)
snifferEncodings=0
snifferEncodings = FN NewPtrClear (SIZEOF(TextEncoding) * maxSnifferEncodings)
LONG IF snifferEncodings>0
err = FN TECGetAvailableSniffers (snifferEncodings, maxSnifferEncodings, @actualSnifferEncodings)
loop = 0
WHILE loop < actualRegionEncodings
found = _false
FOR loop2 = 0 TO actualSnifferEncodings-1
LONG IF [regionEncodings+(loop*SIZEOF(TextEncoding))] = [snifferEncodings+(SIZEOF(TextEncoding)*loop2)]
found = _true
EXIT FOR
END IF
NEXT
LONG IF found>0
INC(loop)
XELSE
actualRegionEncodings = actualRegionEncodings - 1
& (regionEncodings+SIZEOF(TextEncoding)*loop) , [regionEncodings+(SIZEOF(TextEncoding)*actualRegionEncodings)]
END IF
WEND
LONG IF actualRegionEncodings = 0
EXIT FN
END IF
err = FN TECCreateSniffer (@sniffer, regionEncodings, actualRegionEncodings)
errors=0
errors = FN NewPtrClear (SIZEOF(ItemCount) * actualRegionEncodings)
LONG IF errors>0
features=0
features = FN NewPtrClear (SIZEOF(ItemCount) * actualRegionEncodings)
LONG IF features>0
err = FN TECSniffTextEncoding (sniffer, @string+1, |@string|, regionEncodings, actualRegionEncodings, errors, actualRegionEncodings, features, actualRegionEncodings)
bestEncoding = [regionEncodings]
CALL DisposePtr (features)
END IF
CALL DisposePtr (errors)
END IF
LONG if sniffer>0
CALL TECDisposeSniffer(sniffer)
END IF
CALL DisposePtr (snifferEncodings)
END IF
CALL DisposePtr (regionEncodings)
END IF
END FN=bestEncoding
WINDOW #1,"test"
a$ = "テスト文字列"
inputEncoding = FN FindBestEncoding&(a$)
xErr = FN TECGetTextEncodingFromInternetName(@outputEncoding,"UTF-8")
xErr = FN TECCreateConverter (@converter, inputEncoding, outputEncoding)
xErr = FN TECConvertText (converter, @a$+1, |@a$|, @inputact,@b$+1,255, @outputact)
xErr = FN TECDisposeConverter(converter)
d = outputact
| @b$,d
PRINT b$
STOP